<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2021.3.25
 * Time: 12:37
 */
class Solution {
    function longestCommonPrefix($strs) {
        $prefix = '';
        $i = 0;
        if(count($strs)<1){
            return $prefix;
        }
        while(true){
            $current = $strs[0]{$i};
            if(!$current){
                return $prefix;
            }
            foreach($strs as $str){
                if($str{$i} != $current){
                    return $prefix;
                }
            }
            $prefix .= $current;
            $i++;
        }
        return $prefix;
    }
}
$strs = ["cyu","car","cvf"];

$res = (new Solution())->longestCommonPrefix($strs);
var_dump($res);